package com.atguigu.boot.activemq.topic.produce;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.inject.Inject;
import javax.jms.Topic;
import java.util.UUID;

/**
 * @Auther 赵乾坤
 * @Date 2021-04-17 15:33
 */
@Component
public class Topic_Produce {

    @Resource
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Inject //同Resource 一样是java的  @Autowired
    private Topic topic;

    @Scheduled(fixedDelay = 3000)
    public void produceTopic() {
        jmsMessagingTemplate.convertAndSend(topic, "主题消息：" + UUID.randomUUID().toString().substring(0, 5));
    }
}
